package org.blogspot.t0yv0.marcalog.controller

import com.google.appengine.api.blobstore._
import org.blogspot.t0yv0.marcalog.model._
import org.blogspot.t0yv0.marcalog.util._

sealed class PurgeTask(cN: String) extends Task {

  def this() = this("java.lang.Int")

  override val parameters = Map(("class", cN))

  override def execute(ctx: HttpContext, pm: DataManager) {    
    val cN  = ctx.request.getParameter("class")
    val cl  = Class.forName(cN).asInstanceOf[Class[Entity]];
    val res = pm.all(cl, 0, 256);
    if (!res.isEmpty) {
      pm.delete(res);
      Tasks.schedule(new PurgeTask(cN));
    }
  }

}
